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 workspace relative files.associations setting #12805

Closed
octref opened this issue Sep 27, 2016 · 10 comments
Closed

Allow workspace relative files.associations setting #12805

octref opened this issue Sep 27, 2016 · 10 comments
Labels
config VS Code configuration, set up issues feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code

Comments

@octref
Copy link
Contributor

octref commented Sep 27, 2016

  • VSCode Version: 1.6 Insiders
  • OS Version: OS X 10.11.6

Currently, if I have a project test, with a file test/src/app.js. I need this workspace setting to get it recognized as TypeSscript:

{
  "files.associations": {
    "/Users/octref/Code/fiddle/test/src/*.js": "typescript"
  }
}

I wish I could do

{
  "files.associations": {
    "src/*.js": "typescript"
  }
}
@bpasero
Copy link
Member

bpasero commented Sep 27, 2016

@octref for that I think you should set:

{
  "files.associations": {
    "**/src/*.js": "typescript"
  }
}

Since it is totally valid to open files without having a workspace open we cannot allow workspace relative paths here.

@bpasero bpasero closed this as completed Sep 27, 2016
@octref
Copy link
Contributor Author

octref commented Sep 27, 2016

@bpasero

But things like test/node_modules/mypackage/src/app.js would also be matched with "**/src/*.js.

@bpasero
Copy link
Member

bpasero commented Sep 27, 2016

That is true but just allowing workspace relative paths is causing many issues because they do not work once you have no workspace open. How would you solve that?

@octref
Copy link
Contributor Author

octref commented Sep 27, 2016

How about only applying global files.associations when no workspace is open?

Or if you meant adding relative path to workspace settings in general, how about allowing ${workspaceRoot}, similar to launch.json?

@bpasero
Copy link
Member

bpasero commented Sep 27, 2016

I am not sure I understand the suggestion. For one a user might not easily understand the difference between workspace and global association setting, it is too subtle. And then while we could support ${workspaceRoot} it would not work when no workspace is open and again I fear this is too subtle...

@bpasero
Copy link
Member

bpasero commented Sep 27, 2016

The only potential solution I see is to allow for workspace relative paths only when you configure workspace settings (as opposed to global settings). But this needs lots of guidance to the user to make this understandable.

I am open for suggestions and PRs if someone wants to jump in.

@bpasero bpasero reopened this Sep 27, 2016
@bpasero bpasero added help wanted Issues identified as good community contribution opportunities feature-request Request for new features or functionality workbench labels Sep 27, 2016
@bpasero bpasero changed the title files.associations should be relative to workspace in workspace settings Allow workspace relative files.associations setting Sep 27, 2016
@bpasero bpasero added the config VS Code configuration, set up issues label Jan 19, 2017
@bpasero bpasero added editor workbench-editors Managing of editor widgets in workbench window and removed workbench labels Nov 16, 2017
@alexdima alexdima removed the editor label Nov 17, 2017
@bpasero bpasero added editor and removed workbench-editors Managing of editor widgets in workbench window labels Nov 17, 2017
@alexdima alexdima removed the editor label Nov 23, 2017
@ralish
Copy link

ralish commented Jan 28, 2018

@bpasero Agree with your views on implementation. I just found this issue after trying to set a relative files.associations path in a workspace settings files. From my PoV, it only makes sense to support such paths within workspace settings files and not global or user settings files.

@DaDummy
Copy link

DaDummy commented Mar 21, 2022

It is sad that there is no way to configure a workspace to e.g. treat only files in the root folder in a special way. I don't understand why it would be complicated to either only allow that in the workspace settings file or ignore such entries whenever there is no workspace.

Why does the workspace "files.associations" configuration support global paths at all? That feels like really bad design IMHO.

Example of a workspace configuration that does not do, what one would expect which is treating files in the workspace root specially:

{
    "files.associations": {
        "/*.{yml,yaml}": "ansible",
    }
}

Instead I have to do this in a workspace configuration making it strictly non-portable:

{
    "files.associations": {
        "/home/user/projects/myproject/*.{yml,yaml}": "ansible",
    }
}

There appears to be no clean alternative as I do not want all yaml files in that workspace to be handled by that extension and it will be tedious to add each and every subfolder to the configuration hoping that it won't also match a path segment on some user's workspace path.

Please consider reopening this issue at least as this currently is a won't-fix-without-existing-workaround.

@nickiaconis
Copy link

nickiaconis commented Dec 19, 2022

I encountered this today. It was extra perplexing since I also have the following in my .vscode/settings.json:

"typescript.tsdk": "./common/temp/node_modules/.pnpm/[email protected]/node_modules/typescript/lib"

It appears that "typescript.tsdk" accepts a relative path and works just fine. So then, what is the technical limitation why "file.associations" can't do the same?

// .vscode/settings.json
{
  "files.associations": {
    "./common/config/rush/*.json": "jsonc" // ← this doesn't work
  },
  "typescript.tsdk": "./common/temp/node_modules/.pnpm/[email protected]/node_modules/typescript/lib" // ← this does
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config VS Code configuration, set up issues feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

7 participants
@bpasero @nickiaconis @ralish @octref @alexdima @DaDummy and others