After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 755952 - Fix algo for gtk_source_language_manager_guess_language()
Fix algo for gtk_source_language_manager_guess_language()
Status: RESOLVED OBSOLETE
Product: gtksourceview
Classification: Platform
Component: General
unspecified
Other Linux
: Normal normal
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2015-10-01 17:19 UTC by Sébastien Wilmet
Modified: 2021-07-05 11:01 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Sébastien Wilmet 2015-10-01 17:19: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.
Comment 1 Sébastien Wilmet 2018-06-23 10:08:40 UTC
See also:
https://gitlab.gnome.org/GNOME/gtksourceview/issues/12#note_250116
Comment 2 Sébastien Wilmet 2018-06-23 17:09:07 UTC
(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.
Comment 3 Sébastien Wilmet 2018-06-28 17:48:06 UTC
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.
Comment 4 GNOME Infrastructure Team 2021-07-05 11:01:18 UTC
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.