0

I want to write Kamailio Language Server for Visual Studio 2022, I Create a project in GitHub with below structure

enter image description here

And I use kamailio.tmLanguage.json from https://github.com/miconda/vscode-kamailio-syntax/blob/master/syntaxes/kamailio.tmLanguage.json that I sure works for Visual Studio Code, So this grammar is correct

But I do not know why my code is not working correctly and does not highlight keyword?

My test with .kcfg file extension like below

using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kamailio.VisualStudio
{
#pragma warning disable 649
    public class KamailioContentDefinition
    {
        [Export]
        [Name("kamailio")]
        [BaseDefinition(CodeRemoteContentDefinition.CodeRemoteContentTypeName)]
        internal static ContentTypeDefinition KamailioContentTypeDefinition;

        [Export]
        [FileExtension(".kcfg")]
        [ContentType("kamailio")]
        internal static FileExtensionToContentTypeDefinition KamailioFileExtensionDefinition;
    }
#pragma warning restore 649
}

Any body can find my mistake?

All code to reproduce my problem is in GitHub

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
sorosh_sabz
  • 2,356
  • 2
  • 32
  • 53
  • Where is a file with suffix ".kcfg"? There's nothing in your github source code. – kaby76 Aug 05 '22 at 16:16
  • 1
    Just a guess, but I suspect that the newer json format is not supported for VS2022 (VSIDE). VSIDE is always years behind VSCode, at least that is what I had to deal with for VS2019. Clone https://github.com/microsoft/VSSDK-Extensibility-Samples then open the TextmateSample project and run it. It works fine, but that sample uses the old xml syntax. – kaby76 Aug 05 '22 at 19:28

1 Answers1

0

The good news:

It seems that all you need to do is add fileTypes to your kamailio.tmLanguage.json file, e.g.

    "fileTypes": [
        ".cfg"
    ],

VS matches TextMate grammars to files based on these properties.

The bad news:

VS is apparently not smart enough to support other ways to filter when you are or aren't applicable. Specifically, it does not seem to support the firstLineMatch property, so it will apply your grammar to all *.cfg files. If there is another way to filter which files are or are not applicable, I wasn't able to find it.

Jimmy
  • 27,142
  • 5
  • 87
  • 100
  • Thanks a lot, I have this problem and another that explain https://github.com/microsoft/VSSDK-Extensibility-Samples/tree/master/TextmateGrammar thanks to @kaby76 – sorosh_sabz Feb 12 '23 at 18:35
  • I add feature request on developer community to add `firstLineMatch` into visual studio, please vote up this https://developercommunity.visualstudio.com/t/Support-firstLineMatch-in-tmlanguage-for/10281813 – sorosh_sabz Feb 16 '23 at 08:36