michaelrommel / nvim-silicon

neovim plugin to create code images using the external silicon tool.
MIT License
110 stars 8 forks source link

Doesn't work with fortran files #11

Closed sahashirshendu closed 4 months ago

sahashirshendu commented 4 months ago

Gives: silicon returned with: [error] Unsupported language: fortran Although running silicon from terminal generates image just fine. Sample file test.f:

      PROGRAM HELLO
      PRINT *, 'Hello, World!'
      END PROGRAM HELLO

PS: silicon seems to be taking the file extension as language parameter, adding the following in setup fixes it ... but it isn't a very good solution ... is it?

      language = function()
        local lang = vim.bo.filetype
        if lang == "fortran" then
          return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()), ":e")
        else
          return lang
        end
      end,
michaelrommel commented 4 months ago

Hi, I have trouble finding, the right method to do that kind of thing. The reason is, silicon uses the rust syntect crate to determine the language along with some heuristics, not only the extension. syntect in turn uses Sublime's grammar repository at https://github.com/sublimehq/Packages/?tab=readme-ov-file but I cannot find any reference for fortran. There may be some mapping going on, but until now, I was not able to find, where this is been done. I will keep looking into it - also for other reasons, but I have no immediate solution.

michaelrommel commented 4 months ago

OK, since bat also uses syntect, I could get a list of supported standard languages from there. It shows different names and mappings to extensions. Let me think of the best way to support this.

image
michaelrommel commented 4 months ago

Hi,

can you try out the latest version? I have now implemented a fallback to the extension in case the first try to use the filetype does not work out. All explained in the new README. Please close the issue, if you are satisfied.

Thanks,

Michael.

sahashirshendu commented 4 months ago

Thanks a lot. The issue is indeed solved.