GNOME Bugzilla – Bug 755952
Fix algo for gtk_source_language_manager_guess_language()
Last modified: 2021-07-05 11:01:18 UTC
See bug #755933. cpphdr.lang had the mimetype "text/x-chdr". test.hpp had the mimetype "text/x-c++hdr" which is-a "text/x-chdr", but not the same. pick_langs_for_filename() returns only one match for *.hpp (the correct one, cpphdr), but since the mimetype is not exactly the same, it calls pick_lang_for_mime_type() which returns the first .lang that has a mimetype that is-a "text/x-c++hdr", that is, c.lang. guess_language() should be fixed, the algo is quite convoluted and is broken in some cases. If a glob match is found, the function should return the best .lang from the list, not _another_ lang. The current algo was done in commit 5090e395fd5e9423b06410e2d90e220a945e513d, to fix bug #598579. So there should not be a regression for that latter bug.
See also: https://gitlab.gnome.org/GNOME/gtksourceview/issues/12#note_250116
(In reply to Sébastien Wilmet from comment #1) > See also: > https://gitlab.gnome.org/GNOME/gtksourceview/issues/12#note_250116 For that, the best solution to better support globs, is to prefer something that hasn't the '*' character. I.e. pom.xml is preferred over *.xml. But it's anyway better to have a more precise mimetype in shared-mime-info.
It's been a long time since I posted this bug, so I've forgotten some details about how I wanted to solve it. But I remember that I planned to use a freedesktop.org library to know more stuff about mimetypes and their parent-children relationships. I remember that GLib or GIO uses that lower-level freedesktop.org library, but doesn't expose all its features. Basically if a *.lang file is provided for a parent mimetype (relative to the mimetype of the current file), and no *.lang files exactly match, then the *.lang file for the nearest parent mimetype should be chosen (except maybe if there is an exact match for the glob). For the unit tests, the plan was to refactor the code to be able to test the functions against mimetypes/globs/filenames all as strings, not to test with real *.lang files and real source files.
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/gtksourceview/-/issues/ Thank you for your understanding and your help.