How to use the Visual Studio 2022 snippet index files?

AdiGeo 20 Reputation points
2024-09-19T18:26:45.82+00:00

Hello,

I am trying to create some snippets for a language for which there is no VS 2022 Language Service registered. I am using the following steps:

https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2017/extensibility/internals/support-for-code-snippets-in-a-legacy-language-service?view=vs-2017

In the VS 2022 extension *pkgdef file I include the following entry where I point to the snippet index file:

[$RootKey$\Languages\CodeExpansions\Lang-Java]
@="{JavaSnippets-GUID}"
"Package"="{Package-GUID}"
"DisplayName"="0"
"LangStringID"="Java"
"IndexPath"="$PackageFolder$\TestVsix\Snippets\Java\Snippets.xml"
"ShowRoots"=dword:00000000

The "Snippets.xml" file looks like:

<?xml version="1.0" encoding="utf-8" ?>
<SnippetCollection>
  <Language Lang="Test-Java" Guid="{JavaSnippets-GUID}">
    <SnippetDir>
      <OnOff>On</OnOff>
      <Installed>true</Installed>
      <Locale>1033</Locale>
      <DirPath>TestSnippets\</DirPath>
      <LocalizedName>Test</LocalizedName>
    </SnippetDir>
  </Language>
</SnippetCollection>

I was expecting that my snippets that exist in the $PackageFolder$\TestVsix\Snippets\Java\TestSnippets directory to be automatically picked by Visual Studio 2022, but that does not happen until I add the following entry to the *.pkgdef file:

[$RootKey$\Languages\CodeExpansions\Lang-Java\Paths]
"Test"="$PackageFolder$\TestVsix\Snippets\Java\TestSnippets\"

What needs to be done for the snippets to be registered with Visual Studio 2022 just by using the snippets index file and by removing the above entry?

Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.