Search code examples
visual-studio-2019syntax-highlightingvisual-studio-extensions

Including TextMate grammars in VSIX packages


In an attempt to add basic Visual Studio editor support for MASM, following the guide Add a Language Server Protocol extension, I created a new VSIX project, added my colorization file under a directory named "Syntaxes", added the required .pkgdef file, and adjusted all the properties as specified in the tutorial, but no matter how I build the project, the colorization file does not work, even though it is included in the package.

When I copy it to %USERPROFILE%.vs\Extensions\MASM\Syntaxes folder, everything works as expected, but it's not a satisfactory solution, because I'd also like to add several new classification types and formats, and then map some of the scopes defined in MASM.tmLanguage to my new classifications using an additional .tmTheme file.

Here is the structure of my project:

The structure of the project

This video shows how to add support for Julia, and it seems to work when they finally create a VSIX project, but, what's interesting, at the beginning of the video, they try placing their Julia.tmLanguage file in %USERPROFILE%.vs\Extensions\Julia\Syntaxes, and it doesn't work.

In my case, it's the other way around – the colorization file seems to be visible to Visual Studio only when I place it in the .vs folder in my home directory. Also, in the Assets section of my manifest file, there is a VsPackage asset linked to the entire project. I tried replacing it with one explicitly referencing my .pkgdef file, but it didn't solve the problem either. Am I missing something?


Solution

  • After reading this guide on debugging .pkgdef files*, I was able to resolve the problem just by making sure that the base name of my .pkgdef file matches the unique product identifer specified in source.extension.vsixmanifest: make sure the Product ID field includes a valid GUID, and rename the .pkgdef file to <Product ID>.pkgdef, e.g. Assembly_Language_Integration.D0775E55-5DAB-4D82-A47B-72DF63DA756E.pkgdef.

    *See Issue: pkgdef File Is Not Found and compare the names of the extensions installed in $RootFolder$\Common7\IDE\Extensions\Community, where $RootFolder$ is the installation directory of Visual Studio.