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

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

Open
rightaway opened this issue Sep 5, 2018 · 11 comments
Open

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

rightaway opened this issue Sep 5, 2018 · 11 comments
Labels
feature-request Request for new features or functionality languages-guessing Language guessing issues workbench-editors Managing of editor widgets in workbench window
Milestone

Comments

@rightaway
Copy link

{
	"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
Copy link

vscodebot bot commented Sep 5, 2018

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

@joaomoreno joaomoreno assigned bpasero and unassigned joaomoreno Sep 6, 2018
@bpasero bpasero changed the title Set a file association for files with no extension Allow to set a file association for files with no extension Sep 6, 2018
@bpasero
Copy link
Member

bpasero commented Sep 6, 2018

@rightaway does it not work when you set:

{
	"files.associations": {
		"somefilename": "mydefaulttype"
	}
}

@bpasero bpasero added the info-needed Issue requires more information from poster label Sep 6, 2018
@rightaway
Copy link
Author

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.

@bpasero bpasero added feature-request Request for new features or functionality languages-basic Basic language support issues and removed info-needed Issue requires more information from poster labels Sep 6, 2018
@bpasero bpasero removed their assignment Sep 6, 2018
@bpasero bpasero added file-io File I/O and removed languages-basic Basic language support issues labels Sep 6, 2018
@Frankstar
Copy link

still open?

@HyiouBear
Copy link

HyiouBear commented Feb 19, 2019

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

@stickycode
Copy link

/[^.]+/ 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

@bpasero bpasero added languages-basic Basic language support issues and removed file-io File I/O labels Oct 8, 2019
@aeschli aeschli added languages-guessing Language guessing issues and removed languages-basic Basic language support issues labels Oct 28, 2019
@sam-rad
Copy link

sam-rad commented Mar 12, 2020

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
Copy link

mjy9088 commented Feb 9, 2022

It's seems to not possible with 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
Copy link

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
Copy link

"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
Copy link

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 #57939 (comment) 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality languages-guessing Language guessing issues workbench-editors Managing of editor widgets in workbench window
Projects
None yet
Development

No branches or pull requests

13 participants