microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.87k stars 29.52k forks source link

Allow to set a file association for files with no extension #57939

Open rightaway opened 6 years ago

rightaway commented 6 years ago
{
    "files.associations": {
        "*": "mydefaulttype"
    }
}

This changes the file association for absolutely all files. Should be possible to set a file association only for files that have no extension. So it would match somefilename but not somefilename.txt and not even .somefilename.

vscodebot[bot] commented 6 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

bpasero commented 6 years ago

@rightaway does it not work when you set:

{
    "files.associations": {
        "somefilename": "mydefaulttype"
    }
}
rightaway commented 6 years ago

Yes, that works fine on the files named exactly somefilename. But can't figure out any way to set a default file type for files with no extension to work.

Frankstar commented 6 years ago

still open?

HyiouBear commented 5 years ago

Is it not possible to have a special syntax instead of that "*" which actually matches every extensions?

stickycode commented 5 years ago

/[^.]+/ maybe allow regular expressions?

Or how about reading the header, shell scripts often don't have an extension but they do have a header e.g. #!/bin/sh or #!/usr/bin/env bash

sam-rad commented 4 years ago

According to VSCode Programming Languages Documentation the glob pattern should be supported, right?

But I wonder why these don't work:

"files.associations": {
  "**/!(*.*)": "markdown",
  "**/+([^.])": "markdown"
}

You can test them on Digital Ocean | Glob Tool

mjy9088 commented 2 years ago

It's seems to not possible with inclusive glob only.

Do you have suggestions on how to represent something without an extension, in settings.json?

Example - Add PCRE regex support, and specify the pattern type

"files.associations": {
    "**/page/*.js": "javascriptreact", // default: glob
    ".*/docs/[^\\.]*$": { "pattern": "regex", "language": "markdown" }, // pattern type specified?
}

IMO this way is straightforward but looks not so good

ThomasReulen commented 1 year ago

Since I also ran into this issue, I will provide my configuration for this.

I wanted to have plaintext for all files without extension. So i just define all files as plaintext as default, and then overwrite specific languages with the correct setting. You can do this easily by opening a new file with an extension not yet in the list. It will be marked as plain text. Then click in the bottom status bar on "Plain Text" and "Configure File Association for ...." and select the language from the list. The user settings will be updated automatically and from this point onwards the file extension will be recognized correctly.


    "files.associations": {
        "**/*": "plaintext",
        "*.go": "go",
        "*.{htm,html}": "html",
        "*.{js,ts}": "javascript",
        "*.py": "python",
        "*.sh": "sh",
        "*.json": "json",
        "*.md": "markdown",
        "*.ps1": "powershell"
    },

Hope this is helpful for someone :-) Cheers

goyalyashpal commented 1 year ago
"somefilename": "mydefaulttype"

hey! how can i know the code for "mydefaulttype" - it's obvious for lots of stuff, but many times it's not.

For example: "Git Commit Message" was shown in the status bar, but the code for it was "git-commit" which i found out after jumping various hoops.

what would have been ur way to find out that code?

DarrenCook commented 10 months ago

I've had to resort to the suggestion of ThomasReulen above. A shame we have to dumb down vscode and will have to manually add a new entry each time we come to a language extension for the first time. (E.g. I just had to add "*.jsonl":"jsonl")

Regarding https://github.com/microsoft/vscode/issues/57939#issuecomment-1033993749 one technique we've used to mix regex and plain filters like this is if it starts and ends in / then treat it as a regex; though not ideal here because it still looks glob-ish.

But can I suggest just adding no-extension as a special case? Ideas:

  1. Allow Item to be blank, and have that mean no extension
  2. Use a special character. E.g. if item is a single _ it means no extension.
  3. Add files.noExtAssociation as a new setting.
Jbleezy commented 4 months ago

Why does !(*.*) not work here? I use the VSCode extension JatinSanghvi.color-my-text and that glob pattern works there to get only files with no extension.

mjy9088 commented 4 months ago

I don't know why, but !(**/*.*), !(*.*), and many variants I've tried just not work