Click here to Skip to main content
15,861,172 members
Articles / Programming Languages / C#

Linkify Add-in for Visual Studio

Rate me:
Please Sign up or sign in to vote.
4.59/5 (23 votes)
2 Aug 2008CPOL9 min read 169.1K   433   99   40
Link source code comments to your bug tracker, MSDN, development Wiki and more.
Sample Image - linkify.gif

New features: Version 1.3 (August 2008)

Introduction

Linkify is a Visual Studio add-in that links your source code comments to your bug tracker, development Wiki, MSDN, Google or any other site or utility. It supports Visual Studio 2005 and 2008.

Instead of inserting a URL, you insert text that starts with a known prefix, e.g.:

C#
// this code fixes bugz:666 - don't remove!
// for more info, see msdn:MakeSureDirectoryPathExists and wiki:ThatUglySaveBug

To follow one of the links, set the caret on the link text and select the "Linkify" from the Tools menu. It helps a lot to create a toolbar button and/or a keyboard shortcut for it!

The above example - if configured so - uses the bugz: protocol to link to your bug tracker, immediately opening case 666. msdn: is a preconfigured protocol that searches MSDN for MakeSureDirectoryPathExists via Google. wiki: might link to your development Wiki.

Why Not Just Paste a URL?

Of course, you could paste the URL as well, but Linkify has some advantages:

  • The source remains more readable.
  • Linkify allows everything that a creative ShellExecute call can do: open URLs, open documents, run programs.
  • If your bug tracker moves to a new URL, just reconfigure the Linkify protocol and you are done for all links.

Installing

The article now contains an installer that puts it in one of the five folders that Visual Studio 2005 and 2008 searches for add-ins in by default. However, if you have changed your add-in search folders or you run into other funny problems, here is how to install manually:

To install manually for Visual Studio 2005, unzip the two files from LinkifyAddin.zip to your Visual Studio Addins folder, e.g. \Documents and Settings\<user>\My Documents\Visual Studio 2005\Addins where <user> is either your user name or "All Users". When you start Visual Studio again, Linkify appears in the Tools menu. From there you can also put it on a toolbar button and/or assign a hotkey to it.

Visual Studio 2008 Notes

Installation is similar for Visual Studio 2008. The addin binary is the same for both versions of Visuaol Studio, and two .AddIn files are included - one for each Visual Studio version. I haven't seen bad side effects when placing both addin files in the search path for one Studio instance (Except that my AddIn manager recognizes it twice).

I haven't been able to test the installation and the latest binaries on VS2008 yet, please report any errors you find.

How to Configure

Holding down Shift while clicking Linkify or starting it while on unrecognized text opens the configuration dialog. There you can manage the list of recognized protocols and associate them with URLs and other commands.

settings3.png

Example

  • Prefix=bugz:
  • EXE/URL=http://companyserver/bugtracker/showbug.asp?id=*
  • Clicking Linkify while the cursor is on bugz:666 opens http://companyserver/bugtracker/showbug.asp?id=666

The asterisk (*) is replaced by the link text from the source code.

Configuration

Prefix:The protocol prefix. You can use any character sequence here, but it is recommended to trail it with a colon.
End of Link:Configures how the end of the link is detected after the protocol was recognized:
  • Space scans until a space is encountered
  • Default uses some heuristically selected characters and should be (mostly) equivalent to the algorithm used in previous versions
  • Remainder of Line uses everything that follows on the line, no questions asked
  • Regular Expression allows to specify a regular expression that selects the link form the remainder of the line

Note that your link text may use single or double quotes directly after the protocol prefix to override Space or Default.

Regular Expression:

(only available if End of Link is set to Regular Expression)
A regular expression to extract the link from the remainder of the line.

DescriptionJust so you recognize what this was supposed to do.
URL Escape:Escapes the link text according to URL rules, which is usually necessary when your target is a URL.
Confirm Execution:Shows a confirmation box before running the command. Recommended if you are doing something irreversible or dangerous, or prefer being asked.
Expand Environment Strings:if checked, environment strings in the URL/exe parameter are expanded before calling ShellExecute. This allows generic references such as %PROGRAMFILES%\SomeTool\SomeTool.exe, and other trickery.
URL/EXE:
Arguments:
filename and arguments parameters for ShellExecute / ProcessStartInfo. The first takes an executable and URL or a document path. If you specify an executable, you may also want to specify the command line arguments for it.
Utility URL:

A link to more information / installation instructions for the prefix. The link is displayed when an error occurs or you enable Test Mode.

If the prefix calls a custom tool, you could link to installaiton instructions here. Also, you could provide a page with additional details here.

More/Export...Exports your settings to a file so you can move it to another PC.
More/Import...Imports settings from a file. You can replace all existing protocols, add or merge them.
More/Add Defaults...Adds the default (sample) protocols to the list, in case you deleted them but want them back.
More/Shift forces Config...Enables / Disables going directly to the configuration dialog when Shift is pressed while clicking on Linkify. (on by default)
More/Test Mode...Enables / Disables and extended confirmation dialog for all protocols (overrides the Confirm Execution option). This dialog contains additional information on what was recognized on the line and is intended for testing.
More/About...Puts Linkify in power save mode to prevent global warming. (to be implemented)

How Link Text is Recognized

The link text parser is all-ugly manual scanning for specific characters. I'm quite happy with the results, but YMMV.

  • To find the prefix, Linkify scans from the caret poistion to the left until it finds a whitespace or the beginning of the line.
  • At this position check if the text matches a known protocol prefix. Comparison is case sensitive. I end my prefixes with a colon, but you don't have to.
  • If it doesn't, but the first character following is an opening parenthesis, skip this and check again. (hack)

The End of Link setting now determines how the link is recognized.

  • Remainder of Line uses the rest of the line.
  • Regular Expression uses the Regex specified in the settings.
    If the regular expression contains a named group "link", it uses this value. Otherwise, if it contains any group, it uses the first one encountered. Otherwise, it uses the entire match.
    If this is all gibberish to you, try Jim Hollenhorst's 30 Minute Regex Tutorial and his Expresso.
  • Space scans to the next whitespace (or end of line).
  • Default scans to the next terminating character: ) . or ;

The settings Space and Default allow single or double quotes to enclose an expresison that does contain terminating characters:

  • google:"Visual Studio 2005" searches for Visual Studio 2005 (no quotes).
  • google:'"Visual Studio 2005"' searches for "Visual Studio 2005" (with quotes).

The Source Code

Source code is included with this add-in, although it isn't recommended reading (FxCop would probably handcuff me). It was a bit tricky to extract the text under the cursor using a sequence of manipulations to the current selection. I've changed that now to extracting the entire line and selection positions and working my way from there.

Visual Studio allows add-ins to save settings in a Globals object, but I found that this works only for strings. Since the settings class is serializable, I serialize to a memory stream and then convert the contents to a base-64 string. It's weird, I know, but I wanted to avoid any Unicode troubles. The settings can be imported from and exported to a file through the configuration dialog. The remaining code (configuration form, etc.) is pretty much straightforward. Most of the initialization is code created by the add-in wizard. If you are curious, you can diff my code against a default add-in wizard-generated project.

Example: Linkifying CodeProject

To search articles on The Code Project, you can add the following settings:

  • Articles by keyword search
    • Prefix: cp:
    • URL: http://www.codeproject.com/info/search.aspx?artkw=*&sbo=kw
  • Articles by author search (currently isn't available)
    • Prefix: cpian:
    • URL: http://www.codeproject.com/info/search.aspx?st=au&target=*
  • cp:Linkify will search for articles containing Linkify
  • cpian:shog9 will search for articles by shog9

It doesn't make much sense; it's just a little tribute...

License

The add-in in binary form is free for any use (including development of a commercial application) and may be redistributed without charge, as long as it remains unmodified and the copyright notice stays intact. Source code of the add-in itself is free for non-commercial use. Please share bug fixes and improvements here. Inclusion in commercial add-ins on request.

Enjoy!

History

  • Aug 15, 2006: Initial release
  • Aug 20, 2006
    • Fixes:
      • No more error message at first start after installing (duh!)
      • Few improvements to file import/export
      • Linking to CP added to defaults
  • Aug 27, 2006 (Version 1.1)
    • Fixes:
      • Error message(s) at first start (sorry folks... it should be really gone)
      • Correct parenting
      • Keyboard shortcuts for the dialog
    • New features:
      • Separate program / argument settings
  • Dec 2007 (Version 1.2)
    • New features:
      • Supports constructor overloads
      • More flexible parser. // (bugz:765) now works, which was driving me crazy!
      • End of link detection configurable as "Space" / "Default" / "Remainder of Line" for each protocol individually*
      • For each protocol, you can set "Confirm Execution" to show a message box that will run before it actually does. Recommended if your action makes non-reversible changes (like deleting files. uh-oh)
      • Shift-Click skips the parser and directly shows the configuration dialog
      • Some UI gimmicks and a general better look
  • Aug 2008 (Version 1.3)
    • Fixes:
      • fixed an Obi Wan when using quotes around the link expression
    • Features
      • Allowing a Regular Expression for matching the link expresison
      • Added better diagnostics when running a link (or failing to do so)
      • Checkboxes to enable/disable individual prefixes
      • Expanding environment strings in the URL/executable
      • Added "utility link"
      • Revamped the dialogs a bit
      • Support for VS 2008 (semi-tested...)

* Note: if I accidentally broke your existing links, first see if changing the configuration for that protocol helps. If not, please leave a message with the protocol prefix and the comment line in question.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Klippel
Germany Germany
Peter is tired of being called "Mr. Chen", even so certain individuals insist on it. No, he's not chinese.

Peter has seen lots of boxes you youngsters wouldn't even accept as calculators. He is proud of having visited the insides of a 16 Bit Machine.

In his spare time he ponders new ways of turning groceries into biohazards, or tries to coax South American officials to add some stamps to his passport.

Beyond these trivialities Peter works for Klippel[^], a small german company that wants to make mankind happier by selling them novel loudspeaker measurement equipment.


Where are you from?[^]



Please, if you are using one of my articles for anything, just leave me a comment. Seeing that this stuff is actually useful to someone is what keeps me posting and updating them.
Should you happen to not like it, tell me, too

Comments and Discussions

 
GeneralWholeTomato SourceLinks Pin
peterchen2-Aug-09 0:07
peterchen2-Aug-09 0:07 
GeneralReally Cool Pin
Paul Conrad2-Aug-08 19:27
professionalPaul Conrad2-Aug-08 19:27 
GeneralThanks very much + potential (small) bug + 1 whish.... Pin
I'm Chris28-Jul-08 23:55
professionalI'm Chris28-Jul-08 23:55 
GeneralRe: Thanks very much + potential (small) bug + 1 whish.... Pin
peterchen29-Jul-08 13:21
peterchen29-Jul-08 13:21 
GeneralRe: Thanks very much + potential (small) bug + 1 whish.... [modified] Pin
I'm Chris29-Jul-08 22:54
professionalI'm Chris29-Jul-08 22:54 
GeneralRe: Thanks very much + potential (small) bug + 1 whish.... Pin
peterchen30-Jul-08 13:47
peterchen30-Jul-08 13:47 
GeneralUpdated Pin
peterchen2-Aug-08 15:18
peterchen2-Aug-08 15:18 
GeneralRe: Updated Pin
I'm Chris29-Oct-08 23:34
professionalI'm Chris29-Oct-08 23:34 
GeneralRe: Updated Pin
peterchen30-Oct-08 5:34
peterchen30-Oct-08 5:34 
GeneralRe: Updated Pin
I'm Chris4-Nov-08 5:01
professionalI'm Chris4-Nov-08 5:01 
GeneralRe: Updated Pin
I'm Chris4-Nov-08 5:02
professionalI'm Chris4-Nov-08 5:02 
QuestionCan you fix this to work with Visual Studio 2008? Pin
Josh K10-Dec-07 7:04
Josh K10-Dec-07 7:04 
AnswerRe: Can you fix this to work with Visual Studio 2008? Pin
peterchen15-Dec-07 23:24
peterchen15-Dec-07 23:24 
OMG | :OMG: What do I have to do? Big Grin | :-D

We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
My first real C# project | Linkify!|">FoldWithUs! | sighist


AnswerRe: Can you fix this to work with Visual Studio 2008? [modified] Pin
peterchen16-Dec-07 4:47
peterchen16-Dec-07 4:47 
GeneralRe: Can you fix this to work with Visual Studio 2008? Pin
Saurabh.Garg13-Jan-08 21:53
Saurabh.Garg13-Jan-08 21:53 
GeneralRe: Can you fix this to work with Visual Studio 2008? Pin
Jonathan C Dickinson18-May-08 20:17
Jonathan C Dickinson18-May-08 20:17 
Answeryes :) Pin
peterchen2-Aug-08 15:20
peterchen2-Aug-08 15:20 
GeneralSeens not to be working with VS2005 SP1 Pin
MarcelEllerbrok11-Jul-07 21:41
MarcelEllerbrok11-Jul-07 21:41 
GeneralRe: Seens not to be working with VS2005 SP1 Pin
peterchen12-Jul-07 0:01
peterchen12-Jul-07 0:01 
QuestionWhat wiki do you use? Pin
Matt Casto28-Aug-06 2:55
Matt Casto28-Aug-06 2:55 
AnswerRe: What wiki do you use? Pin
peterchen28-Aug-06 8:41
peterchen28-Aug-06 8:41 
AnswerRe: What wiki do you use? Pin
Victor Boctor22-Dec-06 15:35
Victor Boctor22-Dec-06 15:35 
GeneralArgument exception Pin
Avi_Harush20-Aug-06 2:00
Avi_Harush20-Aug-06 2:00 
GeneralRe: Argument exception Pin
peterchen20-Aug-06 10:57
peterchen20-Aug-06 10:57 
GeneralRe: Argument exception Pin
peterchen20-Aug-06 11:12
peterchen20-Aug-06 11:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.