Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange (markdown?) content type set for unrelated text files #703

Closed
iloveeclipse opened this issue Feb 13, 2024 · 19 comments
Closed

Strange (markdown?) content type set for unrelated text files #703

iloveeclipse opened this issue Feb 13, 2024 · 19 comments

Comments

@iloveeclipse
Copy link
Contributor

I've played with latest tm4e snapshot from today from https://download.eclipse.org/tm4e/snapshots/ and see some strange issue probably related to wrong content type detected by tm4e.

HebrewSample.txt

data.txt

test.txt

test.txt is even empty file.

The files attached above are just random text files I had in my workspace that are supposed to be "plain text" files without any syntax etc, but they seem to be recognized as markdown? content type and show an ugly black icon.

Here how it looks like:

image

Two issues here:

  1. Ugly black icon probably wasn't meant to be ugly, but just has wrong background set (should be transparent, isn't).
  2. The content type detection seem to go mad. I would expect none of the files above should be linked to the markdown? content type.
@sebthom
Copy link
Member

sebthom commented Feb 13, 2024

This looks like a bug in Eclipse Platform to me.

There is this content type registration without any file extensions/file patterns
https://github.com/eclipse/tm4e/blob/d5aa3918fb716a8239ae1226180372d84f1b9ae6/org.eclipse.tm4e.language_pack/plugin.xml#L833

which also provides an icon
https://github.com/eclipse/tm4e/blob/d5aa3918fb716a8239ae1226180372d84f1b9ae6/org.eclipse.tm4e.language_pack/plugin.xml#L842

and somehow Eclipse associates it with all text files in your case.

@iloveeclipse
Copy link
Contributor Author

Note following: I've set generic editor as default for text content type, and there is code in generic editor that is used by platform to check if it can be used for given files - if it "agrees" it may provide content type platform should use (if I remember it correct). So here I assume it goes to tm4e and that one says markdown.
To reproduce, take latest SDK nightly and set generic editor as default as shown in the screenshot.

@sebthom
Copy link
Member

sebthom commented Feb 13, 2024

there is code in generic editor that is used by platform to check if it can be used for given files - if it "agrees" it may provide content type platform should use

can you point me to that code?

@iloveeclipse
Copy link
Contributor Author

I think this is org.eclipse.ui.internal.genericeditor.GenericEditorWithIconAssociationOverride.getEditorDescriptorForFile(IEditorDescriptor, String) and org.eclipse.ui.internal.genericeditor.GenericEditorWithContentTypeIcon.getImageDescriptor()

@sebthom
Copy link
Member

sebthom commented Feb 13, 2024

Also, is it just the icon that gets changed or is the *.txt file actually markdown syntax highlighted?

@iloveeclipse
Copy link
Contributor Author

In the data.txt you see the numbers seem to be colored, so it looks like syntax highlighting is applied too.

@iloveeclipse
Copy link
Contributor Author

I think it is the return value of org.eclipse.ui.internal.genericeditor.GenericEditorWithIconAssociationOverride.overrideDefaultEditor(String, IContentType, IEditorDescriptor) that makes the difference now, the question why is the content type assumed to be markdown?

@iloveeclipse
Copy link
Contributor Author

One data point more: this seem to be visible in (not released) tm4e snapshot only, as using TextMate 0.9.0.202401090933 doesn't show the "black markdown" icons while properly indicating that the text files will be opened with generic editor.
However, I see that when the files are opened in editor, some syntax highlighting happen.

@sebthom
Copy link
Member

sebthom commented Feb 14, 2024

Do you only have this issue with Eclipse SDK nightly? I don't seem to be able to reproduce it with the currently used target sdk.

@iloveeclipse
Copy link
Contributor Author

iloveeclipse commented Feb 14, 2024

Sorry, my fault, I forgot to mention, the only way to see it is with the new feature implemented in the 4.31 SDK, see eclipse-platform/eclipse.platform.ui#1659 implemented (see https://eclipse.dev/eclipse/news/4.31/platform.php#default_editor_preference).

So in the Content Types, I've manually set generic text editor as default for "Text" content type (before it was "Plain Text Editor"):

image

@sebthom
Copy link
Member

sebthom commented Feb 14, 2024

I changed my target file to:

        <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
            <repository location="https://download.eclipse.org/releases/2024-03/"/>
            <unit id="org.eclipse.equinox.executable.feature.group" version="0.0.0"/>
            <unit id="org.eclipse.sdk.ide" version="0.0.0"/>
        </location>

which gives me:
image

But I don't see that "Default" button:
image

How can I get the right platform binaries into my target file?

@iloveeclipse
Copy link
Contributor Author

I assume you should use https://download.eclipse.org/eclipse/updates/4.31-I-builds repo as there is no final release yet.

@iloveeclipse
Copy link
Contributor Author

Or just grab latest SDK build from https://download.eclipse.org/eclipse/downloads/drops4/I20240213-1800 and install tm4e snapshot build on top (which is what I did).

@sebthom
Copy link
Member

sebthom commented Feb 14, 2024

Ok, I could reproduce it. As I suspected, the issue is in the Eclipse Platform. When querying content types for a file, eventually ContentTypeCatalog#selectMatchingByName will be invoked.

When this method is called with the file extension "txt" it will return the directly mapped contenttype org.eclipse.core.runtime.text and all child content types that have no "builtInAssociations", e.g. have no file-extensions, file-patterns, file-names defined. So it will return these additional content types if the language pack is installed:

  • org.eclipse.tm4e.language_pack.basetype
  • org.eclipse.tm4e.language_pack.markdown-math
  • org.eclipse.tm4e.language_pack.markdown_latex_combined
  • org.eclipse.tm4e.language_pack.cpp_embedded_latex

I don't think this behavior is correct.

@iloveeclipse
Copy link
Contributor Author

I will check that tomorrow, but why is this problem visible with the snapshot tm4e build but not with released version?

@sebthom
Copy link
Member

sebthom commented Feb 14, 2024

why is this problem visible with the snapshot tm4e build but not with released version?

I don't know.

But it gets more funky. Depending on how a content type is registered, it will be automatically associated with *.txt or not by the Eclipse platform.

<extension point="org.eclipse.core.contenttype.contentTypes">
    <!-- this content type will NOT be reported by 
         Platform.getContentTypeManager().findContentTypesFor("txt") -->
    <content-type
       id="contenttype.green"
       base-type="org.eclipse.core.runtime.text"
       name="Green" 
       file-extensions="green" />

    <!-- this content type will be reported by
         Platform.getContentTypeManager().findContentTypesFor("txt") -->
    <content-type
       id="contenttype.blue"
       base-type="org.eclipse.core.runtime.text"
       name="Blue" />
    <file-association
       content-type="contenttype.blue"
       file-extensions="blue" />
</extension>

@sebthom
Copy link
Member

sebthom commented Feb 14, 2024

I merged PR #706 with a temporary workaround. But I don't think this can be the solution. The issue with wrongly associated content types also applies to other plugins. E.g. when you have wildwebdeveloper installed ContentTypeManager will report org.eclipse.wildwebdeveloper.parent as content type of *.txt files.

@iloveeclipse
Copy link
Contributor Author

iloveeclipse commented Feb 15, 2024

Thanks for quick workaround. Unfortunately, 4.31 M3 build is almost over, and I have no tested fix yet, but I've created eclipse-platform/eclipse.platform#1207 to follow up.

@sebthom
Copy link
Member

sebthom commented Feb 16, 2024

I'm going t close this issue for now as there isn't much more we can do in tm4e.

@sebthom sebthom closed this as completed Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants