Wednesday, May 27, 2020

My first Visual Studio Code extension - Git Status Backgrounds (GitStatusBg)

tldr: get it from here and try it out.

I was part of an email discussion about changes that could be added or made to Windows to make it better for developers.
Someone said they wished that Visual Studio (VS) and Visual Studio Code (VSCode) could use different color backgrounds for different projects in a solution.

I know how to build an extension that identifies files from different projects and how to change the background color of the editor, so I reached out to them to understand exactly what they were after.

Upon reflection, they decided that what would help them the most would be if VSCode could better indicate the git status of the file they were working on. They were writing docs and each stage of the documentation was a new file that built upon what was their already. For each new stage, they'd add a new file that was based on the previous step and make the changes there. The problem was that having lots of similar files meant that it was easy to accidentally change the wrong one.
What they wanted was a way to easily identify the new (untracked) files--as they are the ones they will be writing in, and any modified files--as that means they're changing something that already exists.

That's not what I was expecting, nor was it what I was thinking about, but I was intrigued.

I've made lots of extensions for VS but none for VSCode.
For a while, I've wanted to branch out and this seemed like a good opportunity.

I hoped that what I know about building extensions for VS will help with building them for VSCode.
It didn't.

The only thing I've learned building extensions for VS that applied to VSCode was to be persistent and search broadly to find out how to do certain things.

The extension I've made is very simple but in creating it I had to learn a number of things:
  • how to build a basic extension
  • how to respond to opening and switching between documents
  • how to apply visual changes to a document
  • how to get the git status of a file (much harder to work out than I expected)
  • how to share functionality between different extensions
  • how to work with configurable settings in an extension

In places, the VSCode documentation was better than for VS, but in others, it was also quite lacking.
I think the problem with creating documentation for extensibility features is that its necessary to assume a lot about the person doing the development and the documentation needs to be fairly abstract as every extension that is built will be different.
Anyway, if you're considering building an extension for VS or VSCode I highly recommend supplementing the official docs by searching for opensource code that does something similar and learn from that. It's one of the reasons that I share all my extension code on GitHub.

So, what did I build?
This:

VSCode screenshot showing different documents with different color backgrounds
Notice the subtle background tinting of the two open documents.

It colors the background of open documents if the are untracked or have been modified. The colors are customizable but the default matches the colors used in the Explorer and Source Control panels.

Hopefully, with this installed, fewer edits will now be made to the wrong documents. Or any edits in the wrong document will now be spotted sooner.


Tuesday, May 19, 2020

Highlights from BUILD 2020 (so far)

I'm missing being in Seattle for the BUILD conference this year. :(
It's normally one of my favorite events and a highlight of my year.

However, like most events this year, it's gone virtual. Anyone can watch online and there are likely to be many more things that are announced.
This is what's caught my attention initially.
  • Project Reunion - Unifying and evolving the Windows development platform.
  • WinUI 3 preview - The future approach to building native Windows apps.
  • WinGet - The new Windows Package Manager can change how we distribute and install apps.
  • MAUI - Xamarin.Forms is evolving and getting a new name.  github.com/dotnet/maui

more to come....

Wednesday, May 13, 2020

More fun with comments

This is probably the least interesting screenshot I've ever shared
and this one is only slightly more remarkable
Yes, it's the same method from the same file.
But, did you spot the difference?

It's only small.
Look at the left margin.
There are more of the little outlining boxes with minus signs in them in the second image.

The first image is the default behavior. It shows something I hadn't noticed before.
By default, in a method, only multi-line comments starting with a triple-slash can be collapsed.

And the second screenshot?
Well, it turns out that as I wrote a Visual Studio extension that works with comments, these are the kind of things I learn.
As such the second screenshot shows a minor feature of the latest version (1.8) of that extension. It now lets Visual Studio know how to collapse (and expand)  multi-line comments within method blocks. (That's not a piece of code I ever imagined writing!)

Additionally, it also:
- fixes a bug in how it identifies which block to expand and collapse.
- fixes a bug that affects anyone who uses tabs instead of spaces.

Now go: download, install and review the extension for yourself.

Sunday, May 10, 2020

Spaces beats tabs (by a factor of a thousand!)


Yes, there are reasonable arguments for each approach. I know that the accessibility argument for tabs is very strong. But I use spaces. It seems that so many people also do that I'm surprised that this is still an issue.

How many more? (Well, if the title wasn't a give-away) a thousand times more!!!

I have a Visual Studio extension for manipulating comments. It recently passed a thousand installs.
I also recently had a bug filed against it. The bug only affected code that used tabs instead of spaces.

Based on this single, unscientific data-point, it looks like there are at least one thousand people using spaces for each one using tabs.

Yes:
- this isn't scientific.
- this is me twisting the statistics to make a point.
- others may have encountered this but not reported a problem.
- installs and actuals use aren't the same things.

Why is this worth blogging about?
- This number is MUCH bigger than I was expecting.
- This debate is usually based on arbitrary preference and not on data. (I have data because I'm doing something that involves code manipulation and parsing.)


I'm not bothered about which you use (as long as it's not a mixture of the two--now that's barbaric!)