langium icon indicating copy to clipboard operation
langium copied to clipboard

More flexible file matching in langium-config.json

Open ydaveluy opened this issue 9 months ago • 2 comments

In package.json it is possible to define a language with extensions and filenames:

{
          "id": "mylanguage",
          "aliases": [
              "MyLanguage"
          ],
          "filenames": [
              "a_file_name.myext"
          ],
          "configuration": "./language-configuration.json"
}

In langium-config.json, it is only possible to provides an array of extensions.

 {
        "id": "mylanguage",
        "grammar": "src/model/mylanguage.langium",
        "fileExtensions": [ ".myext"],
        "textMate": {
            "out": "syntaxes/mylanguage.tmLanguage.json"
        }
    },

To handle a specific filename it is required to override some Langium services and to use a custom filter to process only a_file_name.myext and not *.myext.

Langium could provide by default filenames in langium-config.json

ydaveluy avatar Mar 26 '25 17:03 ydaveluy

Hi @ydaveluy this seems like a reasonable enough request. I'll see if I can't take a look at the PR later today.

montymxb avatar Mar 28 '25 08:03 montymxb

Hi @montymxb FYI VSCode provides support for extensions, file names, filename patterns, firstLine and mimetypes: https://code.visualstudio.com/api/references/contribution-points#contributes.languages

Associate file name extensions (extensions), file names (filenames), file name [glob patterns](https://code.visualstudio.com/docs/editor/glob-patterns) (filenamePatterns), files that begin with a specific line (such as hashbang) (firstLine), 
and mimetypes to that languageId.

In #1873, I only added support for file names, but the new API can be extended later without breaking it again to provide support for filenamePatterns, firstLine, and mimetypes. These last three elements are more complex to implement and would likely require a third-party library.

ydaveluy avatar Mar 28 '25 08:03 ydaveluy